package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.GenTableColumn;
import io.mybatis.example.springboot.service.GenTableColumnService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * gen_table_column - 代码生成业务表字段
 *
 * @author mkj
 */
@RestController
@RequestMapping("genTableColumns")
public class GenTableColumnController {

  @Autowired
  private GenTableColumnService genTableColumnService;

  @PostMapping
  public DataResponse<GenTableColumnDO> save(@RequestBody GenTableColumnDO genTableColumn) {
    return DataResponse.ok(genTableColumnService.save( genTableColumn));
  }

  @GetMapping
  public RowsResponse<GenTableColumnDO> findList(@RequestBody GenTableColumnDO genTableColumn) {
    return RowsResponse.ok(genTableColumnService.findList( genTableColumn));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<GenTableColumnDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(genTableColumnService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<GenTableColumnDO> update(@PathVariable("id") Long id, @RequestBody GenTableColumnDO genTableColumn) {
    genTableColumn.setId(id);
    return DataResponse.ok(genTableColumnService.update( genTableColumn));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(genTableColumnService.deleteById(id) == 1);
  }

}
